<?php
/*
 +----------------------------------------------------------------------
 + Title        : BaseModel 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2019/5/29 5:44
 + Last-time    : 2019/5/29 5:44+ 86187
 + Desc         : BaseModel
 +----------------------------------------------------------------------
*/


namespace app\common\model;


use app\common\lib\Where;
use think\Model;
use think\model\concern\SoftDelete;

class BaseModel extends Model
{
//    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $datetimeFormat = 'Y-m-d H:i:s';
//    protected $autoWriteTimestamp = 'datetime';
    //查询
    public function findData($where)
    {
        $data = self::all($where);
        return $data;
    }
    //分页查询
    public function getPageData($where=[] , $field='*' , $order='id desc' , $limit=15)
    {
        $data = $this
            ->field($field)
            ->where($where)
            ->order($order)
            ->paginate($limit);
        return $data;
    }

    //添加
    public function add($param)
    {
        $data = $this->allowField(true)->save($param);
        return $data;
    }
    //编辑
    public function edit($save , $where)
    {
        $data = $this->where($where)->update($save);

        return $data;
    }
    //删除
    public function del($where)
    {
        $data =$this->where($where)->delete();
        return $data;
    }

    public function  whereParse(Where $where ){
        return $this->where($where->getWhere());
    }
}